﻿Create database ZWZDB
go
use ZWZDB
-----------------------------------------
--网站栏目
create table [Comm_Menu]
(
	[ID] nvarchar(50) not null primary key, --主键
	[PID] nvarchar(50),
	[Key] nvarchar(200),
	[Text] nvarchar(500) not null,
	[Index] int not null default 0,
	[Type] nvarchar(50) not null,--栏目类型，系统栏目，主导航，一般栏目,
	[Status] bit not null,--栏目状态是否启用
	[CreateTime] datetime not null,
	[ImgUrl] nvarchar(500),--栏目图片
	[NavMode] nvarchar(50),--链接打开方式
	[NavUrl] nvarchar(500),--链接地址
	[PageFile] nvarchar(200),--该栏目对应的页面文件
	[AttrData] nvarchar(500),--附加属性
	[CtnType] nvarchar(200),--文章类型
)
--内容表
create table [Comm_Content]
(
	[ID] nvarchar(50) not null primary key,
	[MID] nvarchar(50) not null,--菜单ID
	[ImgUrl] nvarchar(200),--主图片
	[Title] nvarchar(200) not null,--文章标题
	[TitleSub] nvarchar(500),--文章副标题
	[CtnHtml] ntext,--内容Html
	[Index] int not null default 0,
	[CreateTime] datetime not null,
	[ModifyTime] datetime not null,
	[CUserName] nvarchar(200),
	[CUserID] nvarchar(200),
	[SourceUrl] nvarchar(500),--链接地址,例如友情链接,或转载内容
	[SourceName] nvarchar(200),--链接网站名称,转载来源
	[Status] nvarchar(200) not null,--内容状态，删除，推荐，禁用，含有非法内容
	[CntVisits] bigint not null,--访问量
	[Attr1] nvarchar(500),--附加属性1
	[Attr2] nvarchar(500),--附加属性2
	[Attr3] nvarchar(500),--附加属性3
	[Attr4] nvarchar(500),--附加属性4
	[Attr5] nvarchar(500),--附加属性5
	constraint FK_Content_Menu foreign key ([MID]) references [Comm_Menu]([ID]),
)
--评论
create table [Comm_Comment]
(
	[ID] nvarchar(50) not null primary key,
	[CID] nvarchar(50) not null,--内容ID
	[PID] nvarchar(50) not null,--父主键
	[Text] ntext,
	[IP] nvarchar(200),
	[CUserName] nvarchar(200),
	[CUserID] nvarchar(200),
	[CreateTime] datetime,
	[CntSupport] bigint not null default 0,
	[CntTrample] bigint not null default 0,
	[Status] nvarchar(200),--状态
	constraint FK_PComment foreign key ([PID]) references [Comm_Comment]([ID]),
	constraint FK_Comment_Content foreign key ([CID]) references [Comm_Content]([ID]),
)
--标签
create table [Comm_Tags]
(
	[ID] nvarchar(50) not null primary key,
	[Text] nvarchar(500) not null,
	[Status] nvarchar(200) not null,
)
--标签关联
create table [Comm_TagContent]
(
	[ID] bigint identity(1,1) primary key,
	[TagID] nvarchar(50) not null,
	[ContentID] nvarchar(50) not null,
	constraint FK_CT_TagID foreign key ([TagID]) references [Comm_Tags]([ID]),
	constraint FK_CT_ContentID foreign key ([ContentID]) references [Comm_Content]([ID]),
)
--日志管理
create table [Comm_Log]
(
	[ID] int identity(1,1) primary key,
	[Type] nvarchar(50) not null,
	[CTime] datetime not null,
	[Message] nvarchar(max) not null,
	[ErrorInfo] nvarchar(max) not null,
)
-----------------------------------------
--投票
create table [Vote_Topic]
(
	[ID] nvarchar(50) not null primary key,
	[Title] nvarchar(max) not null,
	[ImgUrl] nvarchar(200),
	[Type] nvarchar(200) not null,--投票类型，单选问题，多选问题
	[StartTime] datetime not null,
	[EndTime] datetime not null,
	[CUserID] nvarchar(50) not null,
	[CUserName] nvarchar(200) not null,
)
--投票选项
create table [Vote_Options]
(
	[ID] nvarchar(50) not null primary key,
	[Text] nvarchar(500) not null,
	[VoteID] nvarchar(50) not null,
	[VoteCount] bigint not null,
	constraint FK_Option_Vote foreign key ([VoteID]) references [Vote_Topic]([ID]),
)
--投票人员
create table [Vote_Voters]
(
	[ID] bigint identity(1,1) primary key,
	[VoteID] nvarchar(50) not null,
	[IP] nvarchar(200),
	[VUserID] nvarchar(50),
	constraint FK_Voter_Vote foreign key ([VoteID]) references [Vote_Topic]([ID]),
)
-----------------------------------------
--用户组
create table [User_Group]
(
	[ID] nvarchar(50) not null primary key,
	[Name] nvarchar(200) not null,
	[Type] nvarchar(200) not null,--用户组类型，系统，用户
	[PowerString] ntext not null,
)
--用户基本信息
create table [User_Info]
(
	[ID] nvarchar(50) not null primary key,
	[GroupID] nvarchar(50) not null,
	[GroupName] nvarchar(200) not null,
	[GroupType] nvarchar(200) not null,
	[Tel] nvarchar(200),
	[Email] nvarchar(200),
	[Gender] nvarchar(20),
	[Birthday] datetime not null,
	[NickName] nvarchar(200),
	[Password] nvarchar(200) not null,
	[CreateDate] datetime not null,
	[Status] nvarchar(50) not null,
	[PicUrl] nvarchar(200),
	[Introduction] nvarchar(max),
	constraint FK_Info_UserGroup foreign key ([GroupID]) references [User_Group]([ID]),
)
--用户登录
create table [User_Login]
(
	[ID] bigint identity(1,1) primary key,
	[UID] nvarchar(50) not null,
	[LoginTime] datetime not null,
	[Status] nvarchar(200) not null,
	[IP] nvarchar(200) not null,
)
--用户其他信息
create table [User_Profile]
(
	[ID]  nvarchar(50) not null primary key,
	[UID] nvarchar(50) not null,
	[Title] nvarchar(50) not null,
	[Value] nvarchar(500) not null,
)
--用户消息
create table [User_Message]
(
	[ID] nvarchar(50) not null primary key,
	[PID] nvarchar(50),
	[SenderID] nvarchar(50) not null,
	[SenderName] nvarchar(200) not null,
	[ReciverID] nvarchar(50) not null,
	[ReciverName] nvarchar(200) not null,
	[Title] nvarchar(500) not null,
	[Body] ntext,
	[CreateTime] datetime not null,
	[SentTime] datetime not null,
	[Status] nvarchar(50),
	[Type] nvarchar(50),
	constraint FK_PUserMessage foreign key ([PID]) references [User_Message]([ID]),
)
-----------------------------------------
--文件目录管理
create table [File_Dir]
(
	[ID] nvarchar(50) not null primary key,
	[PID] nvarchar(50),
	[Name] nvarchar(200) not null,
	[CreateTime] datetime not null,
	[Type] nvarchar(50) not null,
)
--文件管理
create table [File_Info]
(
	[ID] nvarchar(50) not null primary key,
	[DirID] nvarchar(50) not null,
	[ContentID] nvarchar(50),
	[Name] nvarchar(200) not null,
	[Ext] nvarchar(50) not null,
	[Path] nvarchar(500) not null,
	[CreateTime] datetime not null,
	[Size] decimal(18,2) not null,
	[Type] nvarchar(200) not null,
	[CUserID] nvarchar(50) not null,
	[CUserName] nvarchar(200) not null,
	constraint FK_File_Dir foreign key ([DirID]) references [File_Dir]([ID]),
)
-----------------------------------------
--配置信息分组
create table [Cfg_Group]
(
	[Key] nvarchar(50) not null primary key,
	[PKey] nvarchar(50) not null,
	[Text] nvarchar(200) not null,
)
--配置信息管理
create table [Cfg_Setting]
(
	[Key] nvarchar(50) not null primary key,
	[PKey] nvarchar(50) not null,
	[Text] nvarchar(200) not null,
	[Value] nvarchar(max) not null,
	[Type] nvarchar(50) not null,
	[Rag_Max] decimal(18,2) not null default 0,
	[Rag_Min] decimal(18,2) not null default 0,
	[Rag_Step] decimal(18,2) not null default 0,
	constraint FK_Setting_Group foreign key ([PKey]) references [Cfg_Group]([Key]),
)
-----------------------------------------
--页面管理
create table [Page_Info]
(
	[ID] nvarchar(50) not null primary key,
	[Name] nvarchar(200) not null,
	[PID] nvarchar(50) not null,
	[BackGround_attachment] nvarchar(50)  null,
	[BackGround_color] nvarchar(50)  null,
	[BackGround_image] nvarchar(200)  null,
	[BackGround_position] nvarchar(200)  null,
	[BackGround_repeat] nvarchar(200)  null,
	[Body_Width] int not null default 960,
	[Body_Style] nvarchar(max)  null,
	[Font_Color] nvarchar(50)  null,
	[Font_Family] nvarchar(50) null,
	[Font_Size] nvarchar(50) null,
)
--页面容器
create table [Page_Container]
(
	[ID] nvarchar(50) not null primary key,
	[PID] nvarchar(50) not null,
	[Width] int not null default 30,
	[Disabled] bit not null,
	[Style] nvarchar(500),
	[Type] nvarchar(200),
	constraint FK_Ctnr_Page foreign key ([PID]) references [Page_Info]([ID]),
)
--控件信息
create table [Page_Controls]
(
	[ID] nvarchar(50) not null primary key,
	[PID] nvarchar(50) not null,--页面ID
	[HID] nvarchar(50) not null,--容器ID
	[CtrKey] nvarchar(50) not null,--控件标识
	[CtrAttr] ntext not null,--控件属性
	[Index] int not null default 0,--控件序号
	[Visible] bit not null default 1,
	constraint FK_Ctr_Page foreign key ([PID]) references [Page_Info]([ID]),
)
--页面设计
create table [Page_Info_Design]
(
	[ID] nvarchar(50) not null primary key,
	[PID] nvarchar(50) not null,
	[BackGround_attachment] nvarchar(50)  null,
	[BackGround_color] nvarchar(50)  null,
	[BackGround_image] nvarchar(200)  null,
	[BackGround_position] nvarchar(200)  null,
	[BackGround_repeat] nvarchar(200)  null,
	[Body_Width] int not null default 960,
	[Body_Style] nvarchar(max)  null,
	[Font_Color] nvarchar(50)  null,
	[Font_Family] nvarchar(50) null,
	[Font_Size] nvarchar(50) null,
)
--页面设计-容器
create table [Page_Cntar_Design](
	[ID] nvarchar(50) not null primary key,
	[CtnID] nvarchar(50) not null,
	[Width] int not null,
	[Disabled] bit not null,
	[Style] nvarchar(500),
	[Type] nvarchar(200),
)
--控件信息
create table [Page_Controls_Design]
(
	[ID] nvarchar(50) not null primary key,
	[CID] nvarchar(50) not null,
	[CtrAttr] ntext not null,--控件属性
	[Index] int not null default 0,
)
-----------------------------------------
--统计访问量
create table [Static_Viewr]
(
	[ID] bigint identity(1,1) primary key,
	[ViewTime] datetime not null,
	[IP] nvarchar(200) not null,
	[UserAgent] nvarchar(200) not null,
)
--统计访问页面
create table [Static_ViewPage]
(
	[ID] bigint identity(1,1) primary key,
	[VID] nvarchar(50) not null,
	[ViewTime] datetime not null,
	[Url] nvarchar(500) not null,
)
-----------------------------------------
--产品类别管理
create table [Product_Catalog]
(
	[ID] nvarchar(50) not null primary key,
	[Text] nvarchar(200) not null,
	[Pid] nvarchar(50) not null,
	[Index] int not null,
)
--产品信息
create table [Product_Info]
(
	[ID] nvarchar(50) not null primary key,
	[CID] nvarchar(50) not null,
	[P_Name] nvarchar(500) not null,
)
--产品搜索
create table [Product_Search]
(
	[ID] nvarchar(50) not null primary key,
)
-----------------------------------------
